<?php
Class Page{

	private $content, $menu;
	private $defaultContent;

	function __Construct(){
		$this->setDefaultContent();
		$this->log = new Logger("Page\t", _LOGPATH_);
		$this->log->setLogLevel(Logger::VERBOSE);
		$this->log->verbose("new Object of 'Page' created");
	}

	public function setDefaultContent($level = 0, $content = "404"){
		$this->defaultContent[$level] = $content;
	}

	public function setContent($level = 0){
		if(!isset ($this->defaultContent[$level])) $this->setDefaultContent($level);
		if($level >0){
			$this->setContent($level - 1);
		}
		if (isset ($_GET["content".$level]) && ($_GET["content".$level] != "")) {
			$this->content[$level] = $_GET["content".$level];
			$invalide = array (
					'/',
					'/\/',
					':',
					'.'
			);
			$this->content[$level] = str_replace($invalide, ' ', $this->content[$level]);
		}else{
			$this->content[$level] = $this->defaultContent[$level];
			$this->log->verbose("loading default content $level --> ".$this->defaultContent[$level]);
		}
	}

	public function overrideContent($content, $level = 0){
		$this->log->debug("override content: $level --> ".$content);
		$this->content[$level] = $content;
	}

	public function notDefault(){
		return isset ($_GET['content']) && ($_GET['content']!= "");
	}

	public function setMenu($url, $title, $level = 0, $name = "content", $active = false){
		if($this->content[$level] == $url) $active= true;
		$link['active'] = $active;
		$link['url'] = $url;
		$link['title'] = $title;
		$this->menu[$level][$name][] = (object) $link;
	}

	public function getMenu($level=0, $name = "content"){
		return $this->menu[$level][$name];
	}

	public function getContent($level=0){
		return $this->content[$level];
	}

	public function setSubContent($dir){

	}

	private function contentPath($level = 0){
		if($level >0){
			return $this->contentPath($level - 1)."/".$this->content[$level];
		}else{
			return $this->content[$level];
		}
	}
}